﻿//
// Created by work on 24-8-23.
//

#ifndef IOT_PLAT_CVALUE_H
#define IOT_PLAT_CVALUE_H

#include <utility>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <QDateTime>



class CValue {
public:
    enum EValueType{
        IOT_Int,
        IOT_String,
        IOT_Float,
        IOT_Bool,
        IOT_Json,
        IOT_DateTime
    };
public:
    [[maybe_unused]] explicit CValue(){
        m_valid = false;
    }

    [[maybe_unused]] explicit CValue(int value){
        v_i =  value;
        m_type = IOT_Int;
        m_valid = true;
    };

    [[maybe_unused]] explicit CValue(QString value){
        v_s = std::move(value);
        m_type = IOT_String;
        m_valid = true;
    }

    [[maybe_unused]] explicit CValue(float value){
        v_f = value;
        m_type = IOT_Float;
        m_valid = true;
    }

    [[maybe_unused]] explicit CValue(bool value){
        v_b = value;
        m_type = IOT_Bool;
        m_valid = true;
    }

    [[maybe_unused]] explicit CValue(QJsonObject value){
        v_json = std::move(value);
        m_type = IOT_Json;
        m_valid = true;
    }

    [[maybe_unused]] explicit CValue(QDateTime datetime){
        v_dt = datetime;
        m_type = IOT_DateTime;
        m_valid = true;
    }

    [[maybe_unused]] [[nodiscard]] inline int asInt() const {
        return v_i;
    }

    [[maybe_unused]] inline QString asString(){
        return v_s;
    }

    [[maybe_unused]] [[nodiscard]] inline float asFloat() const{
        return v_f;
    }

    [[maybe_unused]] [[nodiscard]] inline bool asBool() const{
        return v_b;
    }

    inline QJsonObject asJson(){
        return v_json;
    }

    inline QDateTime asDateTime(){
        return v_dt;
    }

    inline EValueType type() {
        return m_type;
        m_valid = true;
    }

    inline bool valid(){
        return m_valid;
        m_valid = true;
    }

private:
    int v_i{};
    QString v_s;
    float v_f{};
    bool v_b{};
    QJsonObject v_json;
    QDateTime v_dt;
    bool m_valid = false;

    EValueType m_type;
};



#endif //IOT_PLAT_CVALUE_H
